package com.xspace.android.imcommon.fileupload;

import android.os.RemoteException;

import com.xspace.android.imcommon.entity.ChatMsg;
import com.xspace.android.imcommon.interfaces.ChatListAidl;
import com.xspace.android.imcommon.interfaces.ImServiceConnection;
import com.xspace.android.imcommon.interfaces.ServiceManager;

import java.util.ArrayList;

public class UploadMg {
	public static UploadMg upload;
	private static ServiceManager mServiceManager;

	private UploadMg() {
		mServiceManager = ImServiceConnection.getInstance()
				.getImServiceConnection();
	}

	public static UploadMg getInstance() {
		if (null == upload) {
			upload = new UploadMg();
		}
		return upload;
	}

	public void uploadFile(ArrayList<ChatMsg> mList, IuploadListener listener) {
		ChatListAidl uploadList = new ChatListAidl(mList);
		try {
			mServiceManager.upload(uploadList, listener);
		} catch (RemoteException e) {
		}

	}
	
	public void initIuploadListener(IuploadListener listener) {
		try {
			mServiceManager.initIuploadListener(listener);
		} catch (RemoteException e) {
		}

	}
	public void resetCallback(long id,IuploadListener listener){
		try {
			mServiceManager.resetCallback(id, listener);
		} catch (RemoteException e) {
		}
	}
	public ArrayList<ChatMsg> queryUploadList(String fromUserId, String toUserId) {
		try {
			ChatListAidl mChatListAidl = mServiceManager.queryUploadList(
					fromUserId, toUserId);
			return mChatListAidl.respList;
		} catch (Exception e) {
			return null;
		}
	}

	public void deleteMsg(long msgId) {
		try {
			mServiceManager.deleteFileMsg(msgId);
		} catch (RemoteException e) {
		}
	}
}